﻿using BBCore.Core.Models.OracleEntity.BOM;
using FluentValidation;
using FreeSql.DataAnnotations;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
using OfficeOpenXml.Table;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;

namespace BBCore.Core.Models.Samples
{
    [ExcelExporter(Name = "ZDL_HYJ_DETAIL_BODY",TableStyle=TableStyles.Light10,AutoFitAllColumn = true)]
    [ExcelImporter(IsLabelingError = true, SheetName = nameof(ZDL_HYJ_DETAIL_BODY))]
    [Index("UK_ITEM", "ZDL_BKC_JOB_BODY_ID,ITEM", true)]//同一批次中不能有相同的部品号
    public class ZDL_HYJ_DETAIL_BODY
    {
        [ImporterHeader(IsIgnore = true)]
        [Column(IsIdentity = true)]
        public int Id { get; set; }

        [ImporterHeader(IsIgnore = true)]
        [Display(Name = "BODY_ID")]
        public int ZDL_BKC_JOB_BODY_ID { get; set; }

        //Format ="@",设置默认格式为文本
        [ImporterHeader(Name = "部品号",Format ="@")]
        [Required(ErrorMessage = "部品号不可为空")]
        [Display(Name = "部品号")]
        public string? ITEM { get; set; }

        [ImporterHeader(IsIgnore = true)]
        [Column(IsIgnore = true)]
        //[Required(ErrorMessage = "部品描述不可为空")]
        [Display(Name = "部品描述")]
        public string? DESCRIPTION { get; set; }
       
        [ImporterHeader(IsIgnore = true)]
        [Column(IsIgnore = true)]
        //[Required(ErrorMessage = "部品类型不可为空")]
        [Display(Name = "部品类型")]
        public string? ITEM_TYPE { get; set; }

        [ImporterHeader(Name = "LEVEL2")]
        public string? LEVEL2 { get; set; }

        [ImporterHeader(Name = "JOB2")]
        public string? JOB2 { get; set; }

        [ImporterHeader(Name = "工程别")]        
        [ValueMapping("ASSY工程", 1)]
        [ValueMapping("MT工程", 2)]
        [ValueMapping("INS工程", 3)]
        [Required(ErrorMessage = "工程别不可为空")]
        [Display(Name = "工程别")]
        public Level_enum LEVEL_ENUMS { get; set; }

        [ImporterHeader(IsIgnore = true)]
        [Display(Name = "建立日期")]
        public DateTime CREATED_DATE { get; set; }=DateTime.Now;
    }
    public enum Level_enum
    {
        [Display(Name = "ASSY工程")]
        ASSY = 1,
        [Display(Name = "MT工程")]
        MT = 2,
        [Display(Name = "INS工程")]
        INS = 3
    }
    public class ZDL_HYJ_DETAIL_BODYValidator:AbstractValidator<ZDL_HYJ_DETAIL_BODY>
    {
        public ZDL_HYJ_DETAIL_BODYValidator()
        {
            RuleFor(x => x.ITEM).NotEmpty();
        }
    }
}
